package jdbc;

import java.sql.Connection;
import java.sql.Statement;

/**
 * 实现用户注册功能
 * 程序运行后，要求用户在控制台上陆续输入:用户名，密码，昵称，年龄
 * 然后将该用户信息保存到userinfo表中
 */
public class RegDemo {
    public static void main(String[] args) throws Exception {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册", "注册");
        System.out.println(userInfo);


        Connection conn = DBUtil1.getConnection();
        Statement statement = conn.createStatement();

        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                "VALUES('" + userInfo.getUsername() + "','" + userInfo.getPassword() + "','" + userInfo.getNickname() + "'," + userInfo.getAge() + ")";
        System.out.println(sql);

        int num = statement.executeUpdate(sql);
        if (num > 0) {
            System.out.println("插入成功!");
        }
        conn.close();
    }
}



